import axios from "axios";

export interface BaseRes {
  stat: string;
  msg: string;
}

const instance = axios.create({
  baseURL: process.env.BACKEND || "",
  validateStatus: (status) => {
    return status < 500;
  },
});

export async function post<T>(url: string, data: any = {}, token?: string) {
  return instance.post<T>(url, data, {
    headers: token ? { cookie: "token=" + token } : {},
  });
}

export function get<T>(url: string, token?: string) {
  return instance.get<T>(url, {
    headers: token ? { cookie: "token=" + token } : {},
  });
}
